package com.martinwj.camera2demo.ui;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.martinwj.camera2demo.MainActivity;
import com.martinwj.camera2demo.R;
import com.martinwj.camera2demo.adapter.FuncHorizontalScrollAdapter;
import com.martinwj.camera2demo.callback.CurrentImageChangeListener;
import com.martinwj.camera2demo.callback.OnItemClickListener;
import com.martinwj.camera2demo.utils.ImageUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * author: wj
 * created on: 2021/5/31 17:30
 * description:
 */
public class PictureActivity extends AppCompatActivity {

    private static final int PHOTO_REQUEST_GALLERY = 2;
    private static final int PHOTO_REQUEST_CUT = 3;// 结果

    private FuncHorizontalScrollView mHorizontalScrollView;
    private FuncHorizontalScrollAdapter mAdapter;
    private ImageView mImage;
    private List<Integer> mDatas = ImageUtils.mDatas;

    private ImageView iv_return;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_gallery);
        mImage = (ImageView) findViewById(R.id.id_content);

        iv_return = (ImageView) findViewById(R.id.iv_return);

        iv_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PictureActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });

        mHorizontalScrollView = findViewById(R.id.id_horizontalScrollView);
        mAdapter = new FuncHorizontalScrollAdapter(ImageUtils.mContext, mDatas);
        mHorizontalScrollView.setOnItemClickListener((view, pos) -> {
            mImage.setImageBitmap(ImageUtils.getThumbBitmap(ImageUtils.mContext, mDatas.get(pos)));
            view.setBackgroundColor(Color.parseColor("#AA024DA4"));
        });
        mHorizontalScrollView.setCurrentImageChangeListener((position, viewIndicator) -> {
            mImage.setImageBitmap(ImageUtils.getThumbBitmap(ImageUtils.mContext, mDatas.get(position)));
            viewIndicator.setBackgroundColor(Color.parseColor("#AA024DA4"));
        });
        mHorizontalScrollView.initDatas(mAdapter);
    }
}